#include "hdf5.h"
#include <stdlib.h>
#include <stdio.h>

main() {

	herr_t 	status;
	hsize_t	dims[3];
	int	i;
	int 	j;	
	hid_t 	file_id 	= H5Fopen("bl2-1300-7681x545x4096.165.enstro.filtered.h5", H5F_ACC_RDWR, H5P_DEFAULT);
	hid_t 	dataset_id	= H5Dopen(file_id, "/value");
	hid_t 	spaceid 	= H5Dget_space(dataset_id);
	int   	ndim		= H5Sget_simple_extent_dims (spaceid, dims, NULL);

	fprintf(stdout, "Abierto fichero bl2-1300-7681x545x4096.165.enstro.filtered.h5 con data set id %d y data space id %d ndim %d (%ld,%ld,%ld)\n",dataset_id,spaceid,ndim,dims[0],dims[1],dims[2]);

	float *		memory	= malloc(2592*182*1360*sizeof(float));
	float *		aux	= memory;
	float *** 	volume	= malloc(2592*sizeof(float**));

	for(i = 0; i < 2592; i++)
	{
		volume[i] = malloc(182 * sizeof(float *));
		for(j = 0; j < 182; j++)
		{
	        	volume[i][j] = aux;
			aux += 1360;
		}
	}

	status = H5Dread(dataset_id, H5T_IEEE_F32LE, spaceid/*H5S_ALL*/, H5S_ALL, H5P_DEFAULT, memory);

	fprintf(stdout, "%f %f %f\n",volume[0][10][1243],volume[0][10][1244],volume[0][10][1245]);

	free(memory);
    	for(i = 0; i < 2592; i++)	
		free(volume[i]);
    
    	free (volume);

	status = H5Dclose(dataset_id);
	status = H5Fclose(file_id);

	return 0;

}
